<template>
  <div class="box">
    <header class="header">
      <van-nav-bar
        title="确认订单"
        @click-left="back"
        left-arrow
      ></van-nav-bar>
    </header>
    <div class="content">
      <van-sticky>
        <div v-if="userinfo.flag === 1" class="orderaddress" @click="toAddresslist">
          <h1>{{ userinfo.name }} <i>{{ userinfo.tel }}</i></h1>
          <p>{{ userinfo.province + userinfo.city + userinfo.county + userinfo.addressDetail }}</p>
        </div>
        <div v-else class="orderaddress" @click="toAddresslist">
          <p>请填写收货地址</p>
        </div>
      </van-sticky>
      <van-card
        v-for="item of orderlist"
        :key="item.proid"
        :num="item.num"
        :price="item.price"
        :title="item.proname"
        :thumb="item.proimg"
      />
      <van-coupon-cell
        :coupons="coupons"
        :chosen-coupon="chosenCoupon"
        @click="showList = true"
      />
      <!-- 优惠券列表 -->
      <van-popup
        v-model="showList"
        round
        position="bottom"
        style="height: 90%; padding-top: 4px;"
      >
        <van-coupon-list
          :coupons="coupons"
          :chosen-coupon="chosenCoupon"
          :disabled-coupons="disabledCoupons"
          @change="onChange"
          @exchange="onExchange"
        />
      </van-popup>
      <div class="confimInfo">
        <div>
          商品金额： <span>{{ totalprice }}</span>
        </div>
        <div>
          活动优惠： <span style="color:red">￥0.00</span>
        </div>
        <div>
          运费： <span style="color:red">+￥0.00</span>
        </div>
        <!-- <div>
          实付金额 {{ totalprice }}
        </div> -->
      </div>
      <div>
        <van-submit-bar
          :button-text="'提交订单'"
          @submit="pay"
        >
        <div class="pay">
          实付 : <span>￥ {{ totalprice }}</span>
        </div>
        </van-submit-bar>
      </div>
    </div>
  </div>
</template>

<script>
import Vue from 'vue'
import { NavBar, Dialog, Sticky, Card, CouponCell, CouponList, Popup, SubmitBar } from 'vant'
import { getOrderData } from '@/api'
Vue.use(NavBar)
Vue.use(Card)
Vue.use(Sticky)
Vue.use(CouponCell)
Vue.use(CouponList)
Vue.use(Popup)
Vue.use(SubmitBar)

const coupon = {
  available: 1,
  condition: '无使用门槛\n最多优惠12元',
  reason: '',
  value: 150,
  name: '优惠券名称',
  startAt: 1489104000,
  endAt: 1514592000,
  valueDesc: '1.5',
  unitDesc: '元'
}
export default {
  data () {
    return {
      userinfo: {},
      orderlist: [],
      status: 0,
      orderid: '',
      totalprice: 0,
      chosenCoupon: -1,
      coupons: [coupon],
      disabledCoupons: [coupon],
      showList: false
    }
  },
  mounted () {
    const { orderid } = this.$route.params
    getOrderData({ orderid }).then(res => {
      console.log(res.data)
      this.userinfo = res.data.data.userinfo
      this.orderlist = res.data.data.orderlist
      this.status = res.data.data.status
      this.orderid = orderid
      this.totalprice = res.data.data.totalprice
    })
  },
  methods: {
    back () {
      Dialog.confirm({
        message: '便宜不等人，请三思而行'
      }).then(() => {
        this.$router.go(-1)
      }).catch(() => {
      })
    },
    toAddresslist () {
      this.$router.push('/addresslist?orderid=' + this.orderid)
    },
    onChange (index) {
      this.showList = false
      this.chosenCoupon = index
    },
    onExchange (code) {
      this.coupons.push(coupon)
    },
    pay () {
      this.$router.replace('/pay/' + this.orderid)
    }
  }
}
</script>

<style lang="scss" scoped>
.box {
  background: #f5f5f5;
}
.van-nav-bar {
  height: .65rem;
  line-height: .65rem;
}
.van-nav-bar__title {
  font-size: 0.23rem;
}
.van-nav-bar .van-nav-bar__arrow {
  color: black;
  font-size: 26px;
}
.content {
  .orderaddress {
    width: 3.7rem;
    height: .8rem;
    background-color: #fff;
    border-radius: .12rem;
    margin: 0 auto;
    display: flex;
    overflow: hidden;
    flex-direction: column;
    margin-top: .15rem;
    margin-bottom: .15rem;
    box-shadow: 0 0 0.2rem 0 rgba(200,194,194,.75);
    p {
      font-size: .2rem;
      margin-top: .15rem;
      margin-left: .18rem;
    }
  }
  .van-cell {
    width: 3.7rem;
    margin: 0 auto;
    border-radius: .12rem;
  }
  .confimInfo {
    width: 3.7rem;
    height: 1.2rem;
    // line-height: .3rem;
    margin: 0 auto;
    margin-top: .15rem;
    margin-bottom: .15rem;
    border-radius: .12rem;
    background: #fff;
    padding-top: .02rem;
    div {
      margin-left: .16rem;
      margin-top: .15rem;
    }
    span{
      float:right;
      padding-right: .16rem;
    }
  }
  .pay {
    position: fixed;
    left: .16rem;
    span{
      color:red;
    }
  }
  .van-button--round {
    border-radius: 5px;
    right: .32rem;
  }
}
</style>
